package com.yonyong.tao.service;

import com.yonyong.tao.mapper.dbtwo.TblOnlineLogMapper;
import com.yonyong.tao.mapper.local.TblRecordMapper;
import com.yonyong.tao.model.TblOnlineLog;
import com.yonyong.tao.model.TblRecord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.text.MessageFormat;
import java.util.Date;
import java.util.List;


/**
 * @Describtion Todo
 * @Author yonyong
 * @Date 2020/3/28 14:09
 * @Version 1.0.0
 **/
@Service
@Slf4j
public class RunnerTwoService {

    @Resource
    TblRecordMapper tblRecordMapper;
    @Resource
    TblOnlineLogMapper tblOnlineLogMapper;

    public void run() {
        Example example = new Example(TblOnlineLog.class);
        example.createCriteria().andEqualTo("isOnline","online");
        List<TblOnlineLog> list = tblOnlineLogMapper.selectByExample(example);
        Date now = new Date();
        now.setMinutes(0);
        now.setSeconds(0);
        int affectrows = 0;
        for (TblOnlineLog source:list) {
            TblRecord tblRecord = new TblRecord();
            tblRecord.setName(source.getRealname());
            tblRecord.setIdnumber(source.getUsername());
            tblRecord.setPolicenumber(source.getPoliceNo());
            tblRecord.setUnit(source.getDepartCode());
            tblRecord.setDepartpath(source.getFullCode());
            tblRecord.setPhonenum(source.getPhonenum());
            tblRecord.setCollecttime(now);
            tblRecordMapper.insertSelective(tblRecord);
            affectrows++ ;
        }
        log.info(MessageFormat.format("本次执行结果：insert{0}条。",affectrows));
    }
}
